/**
 *
 */
package com.angel.architecture.services.locator;

import java.util.ArrayList;
import java.util.List;

import com.angel.architecture.initializer.injector.Injector;
import com.angel.architecture.initializer.modules.AbstractModuleDescriptor;
import com.angel.architecture.initializer.modules.DataGeneratorModuleDescriptor;
import com.angel.architecture.initializer.modules.ModuleDescriptor;
import com.angel.architecture.initializer.types.TypeInferencer;

/**
 * @author William
 *
 */
public class ApplicationRegistryReader {

	private static ApplicationRegistryReader INSTANCE;
	private TypeInferencer inferencer;

	/**
	 *
	 */
	private ApplicationRegistryReader() {
		super();
		this.inferencer = new TypeInferencer();
	}

	public synchronized static ApplicationRegistryReader getInstance() {
		if (INSTANCE == null)
			INSTANCE = new ApplicationRegistryReader();

		return INSTANCE;
	}

	public List<Injector> getAllInjectors() {
		List<Injector> result = new ArrayList<Injector>();
		for (AbstractModuleDescriptor descriptor : getAllModuleDescritors())
			descriptor.registerInjectors(result);

		return result;
	}

	protected List<AbstractModuleDescriptor> getAllModuleDescritors() {
		List<AbstractModuleDescriptor> result = new ArrayList<AbstractModuleDescriptor>();
		result.add(new ModuleDescriptor());
		result.add(new DataGeneratorModuleDescriptor());
		return result;
	}

	/**
	 * @return the inferencer
	 */
	protected TypeInferencer getInferencer() {
		return inferencer;
	}

	/**
	 * @param inferencer the inferencer to set
	 */
	protected void setInferencer(TypeInferencer inferencer) {
		this.inferencer = inferencer;
	}
}
